<template>
	<view class="nearbysetPrint">
		<view class="list">
			<view class="list_item" v-for="(item,index) in listArr" :key="index">
				<image @click="selFun(index)" :src="item.isValue?'../../static/img/ic_choose.png':'../../static/img/ic_choose_n.png'"></image>
				<view class="">{{item.title}}</view>
				<view v-if="item.tip" class="list_remark">注：{{item.tip}}</view>
				<input v-show="current == 3 && index == 3" type="text" v-model="boardNum" placeholder="请输入桌位号" />
			</view>
		</view>
		<view style="height: 140rpx;"></view>
		<view class="btn">
			<button type="primary" @click="getPrintqrcode">开始打印</button>
		</view>
	</view>
</template>

<script>
	import { printqrcode } from '../../api/index.js'
	export default {
		data() {
			return {
				qrcode:'../../static/img/my.png',
				listArr:[
				    {
				        title:'打印所有桌位已绑定的二维码',
				        tip:'未绑定桌卡的桌位跳过',
				        isValue:false
				    },
				    {
				        title:'为所有桌位分配二维码并打印',
				        isValue:false
				
				    },
				    {
				        title:'为所有未绑定二维码的桌位分配二维码并打印',
				        isValue:false
				    },
				    {
				        title:'打印指定桌位的二维码',
				        isValue:false,
				        value:'',
				    }
				],
				current:-1,
				boardNum:'',
				shopData:''
			}
		},
		onLoad:function(data){
			console.log(data);
			this.shopData = data;
		},
		methods: {
			getPrintqrcode:function(){
				if(this.current == -1){
					uni.showToast({
						icon:'none',
						title:'请选择打印二维码类型'
					})
					return ;
				}
				
				let type = '';
				if(this.current == 0){
					type = 'bind'
				}else if(this.current == 1){
					type = 'all'
				}else if(this.current == 2){
					type = 'unbind'
				}else if(this.current == 3){
					type = 'one'
				}
				// 开始打印入参
				let obj={
				    uid:this.shopData.uid,
				    suid:this.shopData.suid,
					// uid:'2000065',
					// suid:'10000033',
				    type:type
				}
				if(this.current == 3){
					if(!this.boardNum){
						uni.showToast({
							icon:'none',
							title:'请输入桌位号'
						})
					}
					obj.board_num = this.boardNum
				}
				console.log(obj)
				printqrcode(obj).then((res) => {
					console.log(res)
					if(res.code == 0){
						cm.on('bluetoothPrinte2',function(res){
							console.log(res)
						})
						cm.bluetoothPrinte2({
							data:res,
							success:function(res){
								console.log(res)
							}
						})
					}else{
						uni.showToast({
							icon:'none',
							title:res.msg
						})
					}
				}).catch((e) => {
					console.log(e);
				})
			},
			selFun:function(index){
				this.current = index;
				for (let item of this.listArr) {
					item.isValue = false
				}
				this.listArr[index].isValue = true
			}
		}
	}
</script>

<style lang="scss" scoped>
	.nearbysetPrint{
		position: relative;
		padding-top: 20rpx;
		font-size: $uni-font-size-base;
		.list{
			padding: 50rpx;
			padding-left: 90rpx;
			.list_item{
				position: relative;
				margin-bottom: 30rpx;
				image{
					position: absolute;
					left: -50rpx;
					top: 2rpx;
					width: 36rpx;
					height: 36rpx;
				}
				input{
					width: 400rpx;
					border-radius: 10rpx;
					height: 60rpx;
					font-size: $uni-font-size-sm;
					padding-left: 30rpx;
					margin-top: 20rpx;
					background: #EEEEEE;
				}
				.list_remark{
					font-size: $uni-font-size-sm;
				}
			}
		}
		.btn{
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			border-top: 1rpx solid #FFFFFF;
			padding: 10rpx 30rpx 30rpx 30rpx;
			button{
				font-size: $uni-font-size-base;
				padding: 10rpx;
			}
		}
	}
</style>
